﻿using System;
using System.Collections.Generic;
using NakedObjects;
using NakedObjects.Value;

namespace HRMDomain
{
    public class Note:Base
    {

        [Title, Mask("d"), Hidden]
        public virtual DateTime EnteredDate { get; set; }
        [MultiLine]
        public virtual string Text { get; set; }

        #region Documents (collection)
        private ICollection<Document> _Documents = new List<Document>();

        public virtual ICollection<Document> Documents
        {
            get
            {
                return _Documents;
            }
            set
            {
                _Documents = value;
            }
        }
        #endregion
        #region AddDocument (Action)

        [MemberOrder(Sequence = "1")]
        public void AddDocument(string Name, FileAttachment file)
        {
            Document newdoc = Container.NewTransientInstance<Document>();
            newdoc.Name = Name;
            newdoc.Data = file.GetResourceAsByteArray();
            newdoc.MIMEType = file.MimeType;

            Container.Persist<Document>(ref newdoc);

            Documents.Add(newdoc);
            Container.InformUser("Document Attachment Added.");

        }

        // Use 'hide', 'dis', 'val', 'actdef', 'actcho' shortcuts to add supporting methods here.
        #endregion
    }
}
